@isTest
private class TestWebServicesUtil {
	
	static testMethod void testNewOpportunityCreated() {
		
		/*Creating Test Database*/
		Program__c programName = TestDatabaseCMS.createProgramForTesting();
		Account testAccount = TestDatabaseCMS.createAccountForTesting();
		String opportunityRecordType = Schema.Sobjecttype.Opportunity.getRecordTypeInfosByName().get('West - Student Application').getRecordTypeId();
		
		/*Testing*/
    	test.startTest();
    	WebServicesUtil testUtil = new WebServicesUtil();
    	Boolean teststatus = testUtil.newOpportunityForAccount(testAccount.Id, programName.id, 
    						opportunityRecordType, 'TestLast', 'Appointment', 'Start', '2013-11-01', 'FullApp');
    	test.stopTest();
		
		/*Asserting correctness*/
    	System.assert(teststatus);
	}
	
	static testMethod void testNewOpportunityERR() {
		
		/*Creating Test Database*/
		Program__c programName = TestDatabaseCMS.createProgramForTesting();
		Account testAccount = TestDatabaseCMS.createAccountForTesting();
		String opportunityRecordType = Schema.Sobjecttype.Opportunity.getRecordTypeInfosByName().get('West - Student Application').getRecordTypeId();
		
		/*Testing*/
    	test.startTest();
    	WebServicesUtil testUtil = new WebServicesUtil();
    	Boolean teststatus = testUtil.newOpportunityForAccount(testAccount.Id, programName.id, 
    						opportunityRecordType, 'TestLast', 'Appointment', '', '1-01', 'FullApp');// for covering Exception
    						
    	Boolean teststatus2 = testUtil.newOpportunityForAccount(programName.id, programName.id, 
    						opportunityRecordType, 'TestLast', 'Appointment', '', '2013-11-01', 'FullApp');// for covering DML Exception
    	test.stopTest();
		
		/*Asserting correctness*/
    	System.assert(!teststatus);
	}
	
	static testMethod void testNewCaseCreated() {
		
		/*Creating Test Database*/
		Program__c programName = TestDatabaseCMS.createProgramForTesting();
		Account testAccount = TestDatabaseCMS.createAccountForTesting();
		String opportunityRecordType = Schema.Sobjecttype.Opportunity.getRecordTypeInfosByName().get('West - Student Application').getRecordTypeId();
		Opportunity testOpportunity = new Opportunity(Name=testAccount.lastName, Program__c=programName.id, RecordTypeId=opportunityRecordType,
										AccountId=testAccount.id, StageName='New', Anticipated_Start_Date__c = Date.today().addDays(10), CloseDate = Date.today().addDays(10) );
		insert testOpportunity;
		
		West_Case_Names__c testCaseName = new West_Case_Names__c(name='Duplicate Opportunity', West_Case_Name_Category__c='General', West_Case_Name_Activity__c='Miscellaneous', 
		West_Case_Group__c='Student', West_Queue_Name__c='CM - Queue 1', West_Case_Priority__c='4', West_Case_Type_Deadline__c=1);
		insert testCaseName;
		
		try{
	    	West_Security_Extensions__c objWestSecurityExtenstion = new West_Security_Extensions__c(Default_West_Support_Case_Status__c='New');
	    	insert objWestSecurityExtenstion;	
	    }Catch(Exception Ex){
	           System.Debug('---exp--' +  Ex.getmessage());
	       
	    }
		
		/*Testing*/
    	test.startTest();
    	WebServicesUtil testUtil = new WebServicesUtil();
    	Boolean teststatus = testUtil.newOpportunityForAccount(testAccount.Id, programName.id, 
    						opportunityRecordType, 'TestLast', 'Appointment', '', '2013-11-01', 'FullApp');
    	test.stopTest();
		
		/*Asserting correctness*/
    	System.assert(teststatus);
	}
	
	static testMethod void testNewCaseERR() {
		
		/*Creating Test Database*/
		Program__c programName = TestDatabaseCMS.createProgramForTesting();
		Account testAccount = TestDatabaseCMS.createAccountForTesting();
		String opportunityRecordType = Schema.Sobjecttype.Opportunity.getRecordTypeInfosByName().get('West - Student Application').getRecordTypeId();
		Opportunity testOpportunity = new Opportunity(Name=testAccount.lastName, Program__c=programName.id, RecordTypeId=opportunityRecordType,
										AccountId=testAccount.id, StageName='New', Anticipated_Start_Date__c = Date.today().addDays(10), CloseDate = Date.today().addDays(10) );
		insert testOpportunity;
		
		/*Testing*/
    	test.startTest();
    	WebServicesUtil testUtil = new WebServicesUtil();
    	Boolean teststatus = testUtil.newOpportunityForAccount(testAccount.Id, programName.id, 
    						opportunityRecordType, 'TestLast', 'Appointment', '', '2013-11-01', 'FullApp');
    	test.stopTest();
		
		/*Asserting correctness*/
		system.debug('The status is'+teststatus);
    	System.assert(!teststatus);
	}
	
}